Component({
  data: {
    selected: 0,
    // currentIndex: 0,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    list: [{
      icon: "wr-home",
      pagePath: "/pages/index/index",
      text: "首页"
    }, {
      icon: "wr-sort",
      pagePath: "/pages/sort/index",
      text: "分类"
    }, {
      icon: "wr-cart",
      pagePath: "/pages/cart/index",
      text: "购物车"
    }, {
      icon: "wr-person",
      pagePath: "/pages/usercenter/index",
      text: "个人中心"
    }]
  },
  attached() {
  },
  methods: {
    init() {
      // 匹配当前页面索引，触发tabbar底部聚焦项变更
      const page = getCurrentPages().pop();
      const route = page ? page.route.split('?')[0] : '';
      const active = this.data.list.findIndex(
        (item) =>
          (item.pagePath.startsWith('/') ? item.pagePath.substr(1) : item.pagePath) ===
          `${route}`,
      );
      console.log('当前页面++'+active);
      this.setData({
        selected: active
      })
    },
    switchTab(e) {
      console.log('switchTab');
      console.log(e);
      const data = e.currentTarget.dataset
      const url = data.path
      console.log('跳转页面+++'+url);
      console.log('跳转页面index+++'+data.index);
      wx.switchTab({url})
    }
  }
})